<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>邀请码管理</title>
<script type="text/javascript" src="Public/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="Public/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="Public/js/lazyload.js"></script>
<script type="text/javascript" src="Public/artDialog/artDialog.source.js?skin=default" charset="utf-8"></script>
<script type="text/javascript" src="Public/js/jquery.ae.image.resize.min.js"></script>
<script type="text/javascript" src="Public/js/province_city_county.js"></script>
<link rel="stylesheet" href="Public/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="theme/default/css/common.css">
<link rel="stylesheet" href="Public/css/homeindex.css">


  <!--[if lte IE 6]>
  <link rel="stylesheet" type="text/css" href="/Public/bootstrap/css/bootstrap-ie6.css">
  <![endif]-->
  <!--[if lte IE 7]>
  <link rel="stylesheet" type="text/css" href="/Public/bootstrap/css/ie.css">
  <![endif]-->
</head>

<body>
<include file="./template/default/Public/header-logined.html" />


    <div class="container main">
      <div class="row-fluid">
        <div class="span3">
          <include file="./template/default/Public/sidebar.html" />
        </div><!--/span-->
        <div class="content span9">
          
          <div class="well">
          	<div class="page-header"><h3>邀请码管理</h3></div>
<script type="text/javascript">
function sendInvite(){
	$('#out_notice').html('');
	var invite_mobile =$.trim($('#invite_mobile').val());
	var invite_code = $('#invite_code').val();
	var invite_type = $('#invite_type').val();
	var invite_username = $('#invite_username').val();
	
	if(invite_type==1){
		var reg=/^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/;
		if (!reg.exec(invite_mobile)) {
		$('#out_notice').html('请输入正确的手机号码!');
		$('#invite_mobile').focus();
		return false;
		}
	}
	var baby_id='';
	 $("input[name='baby_id[]']").each(function(){
		//alert($(this).attr("checked"));
        if($(this).attr("checked") == 'checked'){
            baby_id += $(this).val() + ",";            //动态拼取选中的checkbox的值，用"|"符号分隔
        }
    })
	baby_id=baby_id.substr(0,baby_id.length-1);
	$.ajax({
		url:"/index.php",
		type:"GET",
		data:"s=/Home/User/SendInvite/invite_mobile/"+invite_mobile+"/invite_code/"+invite_code+"/baby_id/"+baby_id+"/invite_type/"+invite_type+"/invite_username/"+invite_username,
		dataType:"json",
		success:function(json){
			
			if(json.state=='fail'){
				$('#out_notice').html('手机邀请一天只能发送三次!');
			}else if(json.state=='success'){
				$('#out_notice').html('手机邀请发送成功!');
			}
			
		}
		});
	
		
}

function doOptions(val){
	
	if(val!=""){
		if(val==1){
		//手机邀请
			$('.mobile').show();
			$('.sns').hide();
			$('.message').hide();
		}
		if(val==2){
			$('.mobile').hide();
			$('.sns').hide();
			$('.message').show();
		}
		if(val==3){
			$('.mobile').hide();
			$('.sns').show();
			$('.message').hide();
		}
	}
}
</script>            
<form class="form-horizontal" onSubmit="return false;">

<input type="hidden" name="invite_code" id="invite_code" value="{$invite_code}">

<div class="control-group">
	<label class="control-label">邀请类型 </label>
    <div class="controls">
    	<select name="invite_type" id="invite_type" onChange="doOptions(this.options[this.selectedIndex].value)">
        	<option value="" selected>请选择</option>
            <option value="1">手机邀请</option>
            <option value="2">站内私信邀请</option>
            <option value="3">SNS信息发送</option>
            
        </select>
    </div>
</div>
<div class="control-group">
<label class="control-label">关注宝宝 </label>
<div class="controls">
<volist name="result" id="rs">
<label class="checkbox inline"><input type="checkbox" name="baby_id[]" value="{$rs['baby_id']}" checked> {$rs['baby_realname']}&nbsp;<small>{$rs['baby_nickname']}</small></label>&nbsp;
</volist>
</div>
</div>


<div class="control-group message" id="mobile_input" style="display:none">
 <label class="control-label">站内用户名 </label>
<div class="control">
&nbsp;
<input type="text" name="invite_username" id="invite_username"> 
&nbsp;

</div>
</div>


<div class="control-group mobile" id="mobile_input" style="display:none">
 <label class="control-label">输入手机号码 </label>
<div class="control">
&nbsp;
<input type="text" name="invite_mobile" id="invite_mobile"> 
&nbsp;

</div>
</div>

<div class="control-group">
	<label class="control-label">备注 </label>
    <div class="control">
    &nbsp;
    <textarea name="invite_memo" id="invite_memo"></textarea>
    
    </div>
</div>

<div class="control-group mobile" id="mobile_body" style="display:none">
	<label class="control-label">发送主体</label>
<div class="controls"><p>
亲,免费注册facesbaby.cn账号,来关注我宝宝的成长过程吧,邀请码:<span id="invite_code_pre">{$invite_code}</span>,先注册，再关注！
</p></div>
</div>

<div class="control-group message" id="message_body" style="display:none">
	<label class="control-label">发送主体</label>
<div class="controls"><p>
亲,来关注我宝宝的成长过程吧,邀请码:<span id="invite_code_pre">{$invite_code}</span>
</p></div>
</div>

<div class="control-group sns" id="sns_body" style="display:none">
	<label class="control-label">发送主体</label>
<div class="controls"><p>
亲,来关注我宝宝的成长过程吧,邀请码:<span id="invite_code_pre">{$invite_code}</span>
</p></div>
</div>

<div class="form-actions">
  <button type="button" class="btn" onClick="sendInvite()">登记邀请码</button>
&nbsp;<span class="red" id="out_notice"></span>
</div>

</form>

<script type="text/javascript">
function getLocalFormatTime(nS) { 
    return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");  
}

function invite_list(){
	
	$.ajax({
		url:"/index.php",
		type:"GET",
		data:"s=/Home/User/InviteLIst",
		dataType:"JSON",
		success:function(json){
			var html='';
			if(json!=null){
			$.each(json,function(dataIndex,data){
				html+='<tr><td>'+data.v_type+'</td><td>'+data.v_mobile+'</td><td>'+getLocalFormatTime(data.v_createdate)+'</td><td>'+data.v_code+'</td><td>'+data.v_flag+'</td><td>'+data.v_memo+'[<a href="javascript:void(0)" title="编辑"><i class="icon-edit"></i></a>]</td></tr>';
			});
			$('#vcode_body').html(html);
			}
		}
			
	});	
}
</script>
<div>
<table class="table">
<thead>
	<tr>
    	<th>邀请类型</th>
    	<th>手机号码</th>
        <th>发送时间</th>
        <th>邀请码</th>
        <th>状态</th>
        <th>备注</th>
    </tr>
</thead>
<tbody id="vcode_body">

</tbody>
</table>
</div>
<script type="text/javascript">
invite_list();
</script>            
            
          </div><!--end well-->
         
        </div><!--/span-->
      </div><!--/row-->
      
      </div>
    
<include file="./template/default/Public/footer-logined.html" />
    
    
</body>
</html>